package com.it.pojo;

import java.util.Objects;

public class Equation {

    private int left;

    private int right;

    private String operator;

    private int result;

    public Equation() {
    }

    public int getLeft() {
        return left;
    }

    public void setLeft(int left) {
        this.left = left;
    }

    public int getRight() {
        return right;
    }

    public void setRight(int right) {
        this.right = right;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }

    public String toExercise(){
        if(operator.equals("+")&&right<0){
            return left+operator+"("+right+")"+"=";
        }
        if(operator.equals("-")&&right<0){
            return left+operator+"("+right+")"+"=";
        }
        return left+operator+right+"=";

    }

    public String toEquation(){
        if(operator.equals("+")&&right<0){
            return left+operator+"("+right+")"+"="+result;
        }
        if(operator.equals("-")&&right<0){
            return left+operator+"("+right+")"+"="+result;
        }
        return left+operator+right+"="+result;

    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Equation equation = (Equation) o;
        return left == equation.left &&
                right == equation.right &&
                result == equation.result &&
                equation.operator.equals(operator);

    }

    @Override
    public int hashCode() {
        return Objects.hash(left, right, operator, result);
    }
}
